#define _Mf 100
template<class Likelihood,class Proposal>
class MHRW{
	public:

	MHRW(Likelihood* L, Proposal* P, int M, mat init)
	{
		_init=init;
		_M=M;
		_p=(*L).Get_p();
		_l=(*L)(init,_Mf);
		boost::random::uniform_01<> U;
		runif=new RandomG::Random<boost::random::uniform_01<> >(U);
		_Lik=L;
		_Prop=P;
	}
	void operator()(void)
	{
		mat X(_M,_p);
		double l=_l;
		X(0,span::all)=_init;
		int k=0;
		for(int i=1;i<_M;i++)
		{
			mat Y=X(i-1,span::all)+(_Prop->r(1)).t();
			//cout << Y;
			double t=(*_Lik)(Y,_Mf);
			double r=t-l;

			if(r>log((*runif)()))
			{
				X(i,span::all)=Y;
				l=t;
				k++;
				cout << mean(X(span(0,i),span::all),0);
			}else{
				X(i,span::all)=X(i-1,span::all);
			}
			cout << l;
			cout << "\n" << (double)k/i;
		}
		_X=X;
	}
	mat Get_X(void)
	{
		return _X;
	}
	private:
		RandomG::Random<boost::random::uniform_01<> > *runif;
		double _l;
		Likelihood *_Lik;
		Proposal* _Prop;
		int _p;
		int _M;
		mat _X;
		mat _init;
};
